package com.zzyl.redis;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

@SpringBootTest
public class testList {

    @Autowired
    private RedisTemplate<String,String> redisTemplate; // redisTemplate是springboot自动注入的


    /**
     * 操作列表类型的数据
     */
    @Test
    public void testList(){
        //插入多个值[a,b,c]
        redisTemplate.opsForList().leftPushAll("mylist","a","b","c");
        System.out.println("===================================");
        //在列表左边插入一个值[d,a,b,c]
        redisTemplate.opsForList().leftPush("mylist","d");
        System.out.println("===================================");
        //获取列表中的数据
        System.out.println(redisTemplate.opsForList().range("mylist",0,-1));
        System.out.println("===================================");
        //从左边弹出一个，并获取值，弹出后列表中删除
        System.out.println(redisTemplate.opsForList().leftPop("mylist"));
        System.out.println("===================================");
        //获取列表的长度
        System.out.println(redisTemplate.opsForList().size("mylist"));

    }
}